Skip to content

fix: refreshToken 검증 누락(Critical) + 카카오 500→401 수정 (prod) - #222

Merged
unam98 merged 1 commit into
mainfrom
fix/refresh-token-validation-prod
Aug 5, 2026
Merged

fix: refreshToken 검증 누락(Critical) + 카카오 500→401 수정 (prod)#222
unam98 merged 1 commit into
mainfrom
fix/refresh-token-validation-prod

Conversation

@unam98

@unam98 unam98 commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

작업 배경

변경 사항

영역 내용
AuthService.getNewToken [Critical] Redis에 저장된 refreshToken과 요청값을 실제로 비교하도록 수정
AuthService.signIn 디버그용 System.out.println 제거
KakaoSignInService.getSocialInfo 카카오 API 호출을 try 블록 안으로 이동 (4xx가 500으로 새어나가던 문제 수정)
AuthServiceTest, AppleSignInServiceTest 단위 테스트 16개 신규

영향 범위

  • 보안 (Critical): getNewToken이 지금까지 Redis에 "뭔가 저장돼 있는지"만 확인하고 있어서, 재로그인 등으로 이미 무효화된 예전 refreshToken도 JWT 자체 만료 전까지는 계속 accessToken 재발급에 쓰일 수 있었음. 지금 이 순간 prod에도 동일하게 해당됨 — 이 PR로 실제 저장된 최신 토큰과 일치할 때만 재발급되도록 막힘.
  • 가용성/모니터링: 카카오 토큰 만료 같은 흔한 사용자 케이스가 500이 아니라 401로 정상 처리됨 — 불필요한 에러 알림(Slack/Sentry) 감소.

검증 매트릭스

영향 범위 테스트 코드
refreshToken Critical 버그 수정 검증 redis에_저장된_값이_없음
redis에_저장된_값과_다름
refreshToken 재발급 - 정상/각종 무효 케이스 정상_재발급
accessToken_무효
refreshToken_만료
refreshToken_무효
클레임이_숫자가_아님
존재하지_않는_유저
소셜 로그인 - 신규가입/기존로그인/provider 분기 신규_회원가입
기존_유저_로그인
애플_로그인
닉네임_중복시_재생성
잘못된_provider
Apple P8 키 파싱 + idToken 형식 검증 (dev와 동일 파일, main엔 이미 서명검증 있어서 그대로 통과) 유효한_EC_비밀키면_정상적으로_파싱된다
잘못된_형식의_비밀키면_UnauthorizedException
idToken이_JWT_형식이_아니면_UnauthorizedException

Test Plan

  • 로컬에서 16개 전부 통과
  • main에는 docker-compose.yml이 없어 docker run으로 임시 DB/Redis 띄워서 ./gradlew build 전체(ServerApplicationTests 포함) 통과 확인

🤖 Generated with Claude Code

AuthService(getNewToken/signIn) 13개, AppleSignInService(P8 키 파싱/
잘못된 idToken) 3개, 총 16개 신규 테스트.

테스트 작성 중 발견해서 수정한 버그:
1. [Critical] AuthService.getNewToken: refreshToken을 재발급받을 때
   Redis에 "무언가 저장돼 있는지"만 확인하고, 요청으로 들어온
   refreshToken이 실제로 그 저장된 값과 일치하는지는 비교하지 않고
   있었음. 재로그인 등으로 이미 새 refreshToken이 발급되어 Redis 값이
   교체된 이후에도, 예전 refreshToken이 만료 전이기만 하면 계속
   accessToken 재발급에 쓰일 수 있었던 상태 — refreshToken 무효화가
   사실상 작동하지 않고 있었음. 저장된 값과 요청값을 직접 비교하도록 수정.
2. KakaoSignInService.getSocialInfo: 카카오 API 호출(RestTemplate.exchange)이
   try-catch 밖에 있어서, 카카오 토큰이 만료/무효해 카카오 서버가
   4xx를 반환하면(흔한 케이스) RestTemplate이 던지는 예외가 그대로
   새어나가 401(UnauthorizedException) 대신 500으로 처리되고 있었음.
   API 호출을 try 블록 안으로 이동.

추가로 signIn()의 디버그용 System.out.println 제거.

## dev에 누락돼있던 기존 보안 수정 반영
AppleSignInService의 Apple ID 토큰 서명 검증 로직이 dev에는 없었음.
PR #202(main으로 직접 hotfix, 2026-07-28)로 이미 고쳐졌던 건인데
dev로는 한 번도 반영이 안 된 채 남아있었음 — dev에서 계속 개발하면
서명 검증 없이 파싱만 하는 취약한 버전으로 되돌아간 상태였음.
main의 c74b4ab 커밋을 그대로 cherry-pick해서 dev에도 반영.
@unam98 unam98 self-assigned this Aug 5, 2026
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b765242b-6165-419f-9777-3bd1396bc344

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@unam98
unam98 merged commit ce8328d into main Aug 5, 2026
2 checks passed
@unam98
unam98 deleted the fix/refresh-token-validation-prod branch August 5, 2026 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants